package com.sita.bike.utils;

import com.sita.bike.persistence.Credential;
import com.sita.bike.support.GlobalContext;

import java.util.List;

/**
 * Class com.sita.bike.utils is for
 *
 * @author xiaodong on 15/3/16.
 */
public class SessionUtils {
    public static Credential getCredential() {
        List<Credential> credentials = GlobalContext.getDaoSession().getCredentialDao().loadAll();
        if (credentials.size() == 0) {
            return null;
        }
        return credentials.get(0);
    }

    public static boolean isLoggedIn(Credential credential) {
        return LocalStorage.isLoggedIn();
//        if (TextUtils.isEmpty(credential.getSalt())) {
//            return false;
//        }
//        long lastLoginTime = credential.getLastLoginTime().getTime();
//        if (System.currentTimeMillis() - lastLoginTime > Constants.RE_LOGIN_PERIOD) {
//            return false;
//        }
//        return true;
    }

    public static void logout() {
        LocalStorage.setLoggedIn(false);
    }

    public static void login() {
        LocalStorage.setLoggedIn(true);
    }

}
